// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable restore
namespace Elastic.Clients.Elasticsearch.Ml
{
	public sealed partial class TrainedModel
	{
		[JsonInclude]
		[JsonPropertyName("ensemble")]
		public Elastic.Clients.Elasticsearch.Ml.Ensemble? Ensemble { get; set; }

		[JsonInclude]
		[JsonPropertyName("tree")]
		public Elastic.Clients.Elasticsearch.Ml.TrainedModelTree? Tree { get; set; }

		[JsonInclude]
		[JsonPropertyName("tree_node")]
		public Elastic.Clients.Elasticsearch.Ml.TrainedModelTreeNode? TreeNode { get; set; }
	}

	public sealed partial class TrainedModelDescriptor : SerializableDescriptorBase<TrainedModelDescriptor>
	{
		internal TrainedModelDescriptor(Action<TrainedModelDescriptor> configure) => configure.Invoke(this);
		public TrainedModelDescriptor() : base()
		{
		}

		private Elastic.Clients.Elasticsearch.Ml.Ensemble? EnsembleValue { get; set; }

		private EnsembleDescriptor EnsembleDescriptor { get; set; }

		private Action<EnsembleDescriptor> EnsembleDescriptorAction { get; set; }

		private Elastic.Clients.Elasticsearch.Ml.TrainedModelTree? TreeValue { get; set; }

		private TrainedModelTreeDescriptor TreeDescriptor { get; set; }

		private Action<TrainedModelTreeDescriptor> TreeDescriptorAction { get; set; }

		private Elastic.Clients.Elasticsearch.Ml.TrainedModelTreeNode? TreeNodeValue { get; set; }

		private TrainedModelTreeNodeDescriptor TreeNodeDescriptor { get; set; }

		private Action<TrainedModelTreeNodeDescriptor> TreeNodeDescriptorAction { get; set; }

		public TrainedModelDescriptor Ensemble(Elastic.Clients.Elasticsearch.Ml.Ensemble? ensemble)
		{
			EnsembleDescriptor = null;
			EnsembleDescriptorAction = null;
			EnsembleValue = ensemble;
			return Self;
		}

		public TrainedModelDescriptor Ensemble(EnsembleDescriptor descriptor)
		{
			EnsembleValue = null;
			EnsembleDescriptorAction = null;
			EnsembleDescriptor = descriptor;
			return Self;
		}

		public TrainedModelDescriptor Ensemble(Action<EnsembleDescriptor> configure)
		{
			EnsembleValue = null;
			EnsembleDescriptor = null;
			EnsembleDescriptorAction = configure;
			return Self;
		}

		public TrainedModelDescriptor Tree(Elastic.Clients.Elasticsearch.Ml.TrainedModelTree? tree)
		{
			TreeDescriptor = null;
			TreeDescriptorAction = null;
			TreeValue = tree;
			return Self;
		}

		public TrainedModelDescriptor Tree(TrainedModelTreeDescriptor descriptor)
		{
			TreeValue = null;
			TreeDescriptorAction = null;
			TreeDescriptor = descriptor;
			return Self;
		}

		public TrainedModelDescriptor Tree(Action<TrainedModelTreeDescriptor> configure)
		{
			TreeValue = null;
			TreeDescriptor = null;
			TreeDescriptorAction = configure;
			return Self;
		}

		public TrainedModelDescriptor TreeNode(Elastic.Clients.Elasticsearch.Ml.TrainedModelTreeNode? treeNode)
		{
			TreeNodeDescriptor = null;
			TreeNodeDescriptorAction = null;
			TreeNodeValue = treeNode;
			return Self;
		}

		public TrainedModelDescriptor TreeNode(TrainedModelTreeNodeDescriptor descriptor)
		{
			TreeNodeValue = null;
			TreeNodeDescriptorAction = null;
			TreeNodeDescriptor = descriptor;
			return Self;
		}

		public TrainedModelDescriptor TreeNode(Action<TrainedModelTreeNodeDescriptor> configure)
		{
			TreeNodeValue = null;
			TreeNodeDescriptor = null;
			TreeNodeDescriptorAction = configure;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (EnsembleDescriptor is not null)
			{
				writer.WritePropertyName("ensemble");
				JsonSerializer.Serialize(writer, EnsembleDescriptor, options);
			}
			else if (EnsembleDescriptorAction is not null)
			{
				writer.WritePropertyName("ensemble");
				JsonSerializer.Serialize(writer, new EnsembleDescriptor(EnsembleDescriptorAction), options);
			}
			else if (EnsembleValue is not null)
			{
				writer.WritePropertyName("ensemble");
				JsonSerializer.Serialize(writer, EnsembleValue, options);
			}

			if (TreeDescriptor is not null)
			{
				writer.WritePropertyName("tree");
				JsonSerializer.Serialize(writer, TreeDescriptor, options);
			}
			else if (TreeDescriptorAction is not null)
			{
				writer.WritePropertyName("tree");
				JsonSerializer.Serialize(writer, new TrainedModelTreeDescriptor(TreeDescriptorAction), options);
			}
			else if (TreeValue is not null)
			{
				writer.WritePropertyName("tree");
				JsonSerializer.Serialize(writer, TreeValue, options);
			}

			if (TreeNodeDescriptor is not null)
			{
				writer.WritePropertyName("tree_node");
				JsonSerializer.Serialize(writer, TreeNodeDescriptor, options);
			}
			else if (TreeNodeDescriptorAction is not null)
			{
				writer.WritePropertyName("tree_node");
				JsonSerializer.Serialize(writer, new TrainedModelTreeNodeDescriptor(TreeNodeDescriptorAction), options);
			}
			else if (TreeNodeValue is not null)
			{
				writer.WritePropertyName("tree_node");
				JsonSerializer.Serialize(writer, TreeNodeValue, options);
			}

			writer.WriteEndObject();
		}
	}
}